package com.edu.exam.entity.facility;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.Where;

import java.time.LocalDateTime;

/**
 * 教室分类实体
 * 所属模块：F-08 场地基础信息管理模块
 * 对应数据库表：venue_classroom_category
 *
 * 管理教室的分类信息，包括分类代码、名称、描述、应用场景等。
 * 支持教室的标准化分类管理，提供教室资源分类的完整视图。
 *
 * @author System
 * @version 1.0.0
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Comment("教室分类表")
@SQLDelete(sql = "UPDATE venue_classroom_category SET is_deleted = true, delete_time = CURRENT_TIMESTAMP WHERE id = ?")
@Where(clause = "is_deleted = false")
public class ClassroomCategory {

    /**
     * 分类唯一标识符
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id", nullable = false)
    @Comment("分类唯一标识符")
    private Long id;

    /**
     * 分类代码，系统内唯一
     */
    @Column(name = "category_code", nullable = false, unique = true, length = 50)
    @Comment("分类代码，系统内唯一")
    private String categoryCode;

    /**
     * 分类名称
     */
    @Column(name = "category_name", nullable = false, length = 200)
    @Comment("分类名称")
    private String categoryName;

    /**
     * 分类简称
     */
    @Column(name = "category_short_name", length = 100)
    @Comment("分类简称")
    private String categoryShortName;

    /**
     * 分类详细描述
     */
    @Column(name = "description", columnDefinition = "TEXT")
    @Comment("分类详细描述")
    private String description;

    /**
     * 应用场景说明
     */
    @Column(name = "application_scenario", length = 500)
    @Comment("应用场景说明")
    private String applicationScenario;

    /**
     * 容量范围说明
     */
    @Column(name = "capacity_range", length = 100)
    @Comment("容量范围说明")
    private String capacityRange;

    /**
     * 排序顺序
     */
    @Column(name = "sort_order", nullable = false)
    @Comment("排序顺序")
    private Integer sortOrder = 0;

    /**
     * 分类状态
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "status", nullable = false, length = 20)
    @Comment("分类状态")
    private CategoryStatus status = CategoryStatus.ACTIVE;

    /**
     * 记录创建时间
     */
    @Column(name = "create_time", nullable = false, updatable = false)
    @Comment("记录创建时间")
    private LocalDateTime createTime;

    /**
     * 记录最后更新时间
     */
    @Column(name = "update_time", nullable = false)
    @Comment("记录最后更新时间")
    private LocalDateTime updateTime;

    /**
     * 创建人用户ID
     */
    @Column(name = "create_user")
    @Comment("创建人用户ID")
    private Long createUser;

    /**
     * 最后更新人用户ID
     */
    @Column(name = "update_user")
    @Comment("最后更新人用户ID")
    private Long updateUser;

    /**
     * 乐观锁版本号
     */
    @Version
    @Column(name = "version", nullable = false)
    @Comment("乐观锁版本号")
    private Integer version = 1;

    /**
     * 软删除标记
     */
    @Column(name = "is_deleted", nullable = false)
    @Comment("软删除标记")
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "delete_time")
    @Comment("删除时间")
    private LocalDateTime deleteTime;

    @PrePersist
    protected void onCreate() {
        LocalDateTime now = LocalDateTime.now();
        this.createTime = now;
        this.updateTime = now;
    }

    @PreUpdate
    protected void onUpdate() {
        this.updateTime = LocalDateTime.now();
    }

}